package com.qf.dao.impl;

import com.qf.dao.UserDao;
import com.qf.domain.User;
import com.qf.util.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.Connection;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
   private QueryRunner queryRunner=new QueryRunner();
    @Override
    public User select(String username, String password) {
        Connection connection= DataSourceUtil.getConnection();
        try {
            String sql="select id,username,password,gender from user where username=? and password=?";
            return queryRunner.query(connection,sql,new BeanHandler<>(User.class),username,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DataSourceUtil.closeAll(null,null,connection);
        }


    }
}
